<!DOCTYPE html>
<html>
<head>
    <title>MCP Email Service Test</title>
    <style>
        body {
            font-family: Arial, sans-serif;
            margin: 20px;
            line-height: 1.6;
        }
        .container {
            max-width: 800px;
            margin: 0 auto;
            padding: 20px;
            border: 1px solid #ddd;
            border-radius: 5px;
        }
        h1 {
            color: #333;
        }
        .form-group {
            margin-bottom: 15px;
        }
        label {
            display: block;
            margin-bottom: 5px;
            font-weight: bold;
        }
        input[type="text"], textarea {
            width: 100%;
            padding: 8px;
            border: 1px solid #ddd;
            border-radius: 4px;
        }
        textarea {
            height: 100px;
        }
        button {
            background-color: #4CAF50;
            color: white;
            padding: 10px 15px;
            border: none;
            border-radius: 4px;
            cursor: pointer;
        }
        button:hover {
            background-color: #45a049;
        }
        .response {
            margin-top: 20px;
            padding: 10px;
            border: 1px solid #ddd;
            border-radius: 4px;
            background-color: #f9f9f9;
            display: none;
        }
    </style>
</head>
<body>
    <div class="container">
        <h1>MCP Email Service Test</h1>
        
        <h2>Send Simple Email</h2>
        <form id="simpleEmailForm">
            <div class="form-group">
                <label for="to">To:</label>
                <input type="text" id="to" name="to" required>
            </div>
            <div class="form-group">
                <label for="subject">Subject:</label>
                <input type="text" id="subject" name="subject" required>
            </div>
            <div class="form-group">
                <label for="content">Content:</label>
                <textarea id="content" name="content" required></textarea>
            </div>
            <button type="submit">Send Email</button>
        </form>
        
        <div id="simpleEmailResponse" class="response"></div>
        
        <h2>Send Email with Attachments</h2>
        <form id="attachmentEmailForm" enctype="multipart/form-data">
            <div class="form-group">
                <label for="toAttach">To:</label>
                <input type="text" id="toAttach" name="to" required>
            </div>
            <div class="form-group">
                <label for="subjectAttach">Subject:</label>
                <input type="text" id="subjectAttach" name="subject" required>
            </div>
            <div class="form-group">
                <label for="contentAttach">Content:</label>
                <textarea id="contentAttach" name="content" required></textarea>
            </div>
            <div class="form-group">
                <label for="attachments">Attachments:</label>
                <input type="file" id="attachments" name="attachments" multiple>
            </div>
            <button type="submit">Send Email with Attachments</button>
        </form>
        
        <div id="attachmentEmailResponse" class="response"></div>
        
        <h2>Check Email Service Status</h2>
        <button id="checkStatus">Check Status</button>
        <div id="statusResponse" class="response"></div>
    </div>
    
    <script>
        document.getElementById('simpleEmailForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const to = document.getElementById('to').value;
            const subject = document.getElementById('subject').value;
            const content = document.getElementById('content').value;
            
            fetch(`/api/mcp/send?to=${encodeURIComponent(to)}&subject=${encodeURIComponent(subject)}&content=${encodeURIComponent(content)}`, {
                method: 'POST'
            })
            .then(response => response.json())
            .then(data => {
                const responseElement = document.getElementById('simpleEmailResponse');
                responseElement.textContent = JSON.stringify(data, null, 2);
                responseElement.style.display = 'block';
            })
            .catch(error => {
                console.error('Error:', error);
                const responseElement = document.getElementById('simpleEmailResponse');
                responseElement.textContent = 'Error: ' + error.message;
                responseElement.style.display = 'block';
            });
        });
        
        document.getElementById('attachmentEmailForm').addEventListener('submit', function(e) {
            e.preventDefault();
            
            const to = document.getElementById('toAttach').value;
            const subject = document.getElementById('subjectAttach').value;
            const content = document.getElementById('contentAttach').value;
            const attachments = document.getElementById('attachments').files;
            
            const formData = new FormData();
            formData.append('to', to);
            formData.append('subject', subject);
            formData.append('content', content);
            
            for (let i = 0; i < attachments.length; i++) {
                formData.append('attachments', attachments[i]);
            }
            
            fetch('/api/mcp/send-with-attachments', {
                method: 'POST',
                body: formData
            })
            .then(response => response.json())
            .then(data => {
                const responseElement = document.getElementById('attachmentEmailResponse');
                responseElement.textContent = JSON.stringify(data, null, 2);
                responseElement.style.display = 'block';
            })
            .catch(error => {
                console.error('Error:', error);
                const responseElement = document.getElementById('attachmentEmailResponse');
                responseElement.textContent = 'Error: ' + error.message;
                responseElement.style.display = 'block';
            });
        });
        
        document.getElementById('checkStatus').addEventListener('click', function() {
            fetch('/api/mcp/status')
            .then(response => response.json())
            .then(data => {
                const responseElement = document.getElementById('statusResponse');
                responseElement.textContent = JSON.stringify(data, null, 2);
                responseElement.style.display = 'block';
            })
            .catch(error => {
                console.error('Error:', error);
                const responseElement = document.getElementById('statusResponse');
                responseElement.textContent = 'Error: ' + error.message;
                responseElement.style.display = 'block';
            });
        });
    </script>
</body>
</html>
